package com.s1nx.back.dto.convert;

import com.s1nx.back.dto.BookDTO;
import com.s1nx.back.entity.Book;

import java.util.List;
import java.util.stream.Collectors;

public class BookConverter {
    public static BookDTO convertBookToBookDTO(Book book) {
        if (book == null) {
            return null;
        }
        return new BookDTO(
                book.getId(),
                book.getTitle(),
                book.getAuthor(),
                book.getPrice(),
                book.getNum()
        );
    }

    public static List<BookDTO> convertBookListToBookDTOList(List<Book> books) {
        if (books == null) {
            return null;
        }
        return books.stream()
                .map(BookConverter::convertBookToBookDTO)
                .collect(Collectors.toList());
    }

}
